using System;
using System.Collections.Generic;
using System.Data.Entity.Migrations;
using System.Linq;

namespace MessageBoard.Data
{
    public class MessageBoardMigrationConfiguration
        : DbMigrationsConfiguration<MessageBoardContext>
    {
        public MessageBoardMigrationConfiguration()
        {
            this.AutomaticMigrationDataLossAllowed = true;
            this.AutomaticMigrationsEnabled = true;

        }

        protected override void Seed(MessageBoardContext context)
        {
            base.Seed(context);

#if DEBUG
            if (context.Topics.Count() == 0)
            {
                var topic = new Topic()
                    {
                        Title = "I Love MVC",
                        Created = DateTime.Now,
                        Body = "I love asp .net mvc tapi boong",
                        Replies = new List<Reply>()
                            {
                                new Reply()
                                    {
                                        Body = "I Love it too",
                                        Created = DateTime.Now
                                    },

                                new Reply()
                                    {
                                        Body = "Me too",
                                        Created = DateTime.Now
                                    }
                            }
                    };

                context.Topics.Add(topic);

                var anotherTopic = new Topic()
                    {
                        Title = "I Love Math",
                        Created = DateTime.Now,
                        Body = "I love math mvc tapi boong",
                        Replies = new List<Reply>()
                            {
                                new Reply()
                                    {
                                        Body = "I Love it too",
                                        Created = DateTime.Now
                                    },

                                new Reply()
                                    {
                                        Body = "naaah",
                                        Created = DateTime.Now
                                    }
                            }
                    };


                context.Topics.Add(anotherTopic);

                try
                {
                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                  var msg =  ex.Message;
                }

            }
#endif
        }
    }
}